package com.bz.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bz.dao.ContactsCustomerDao;
import com.bz.dao.ContactsDao;
import com.bz.entity.ContactsCustomerEntity;
import com.bz.entity.ContactsEntity;
import com.bz.model.ContactsDto;
import com.bz.service.IContactsService;

@Service
public class ContactsServiceImpl implements IContactsService {

    @Autowired
    private ContactsDao         contactsDao;

    @Autowired
    private ContactsCustomerDao contactsCustomerDao;

    @Override
    public ContactsDto get() {
        LambdaQueryWrapper<ContactsEntity> query = new LambdaQueryWrapper<>();
        query.orderByDesc(ContactsEntity::getUpdateDate).last("limit 0,1");
        ContactsEntity db = contactsDao.selectOne(query);
        ContactsDto cd = new ContactsDto();
        if (null == db) {
            return cd;
        }
        cd.setAddr(db.getAddr());
        cd.setEmail(db.getEmail());
        cd.setMapImg(db.getMapImg());
        return cd;
    }

    @Override
    public void addContactsCustomer(ContactsCustomerEntity data) {
        data.setCreateBy("web");
        data.setCreateDate(new Date());
        data.setUpdateBy("web");
        contactsCustomerDao.insert(data);
    }

}
